package com.atguigu.controller;

import com.atguigu.pojo.Employee;
import com.atguigu.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.yaml.snakeyaml.events.Event;

import java.util.List;

/**
 * @version 1.0
 * @Author 马冰
 * @Date 2024/12/23 20:41
 * @注释
 */
@RestController
public class EmployeeController {

    @Autowired
    private EmployeeService employeeService;

    @GetMapping("/employee")
    public List<Employee> findEmployee() {
//        int i = 1 / 0;
//        System.out.println(i);
        return employeeService.findAllService();
    }

    @GetMapping("/employee/{id}")
    public Employee findEmployeeById(@PathVariable Integer id) {
        return employeeService.findEmployeeById(id);
    }

    @PostMapping("/employee")
    public String addEmployee(@RequestBody Employee employee) {
        return employeeService.addEmployee(employee);
    }

    @PutMapping("/employee")
    public String updateEmployee(@RequestBody Employee employee) {
        return employeeService.updateEmployee(employee);
    }

    @DeleteMapping("/employee/{id}")
    public String deleteEmployee(@PathVariable Integer id) {
        return employeeService.deleteEmployee(id);
    }

}
